package gold.digger;

import gold.utils.InputUtil;

/**
 * Created by fanzhenyu02 on 2021/12/10.
 * common problem solver template.
 */
public class LC2017 {
    public long startExecuteTime = System.currentTimeMillis();


    /*
     * @param 此题目参考了别人代码
     * 不是因为复杂，而是因为经典
     * 未来需要再次复习此道题目
     * 好巧妙的题目
     * @return:
     */
    class Solution {
        public long gridGame(int[][] grid) {
            int n = grid[0].length;
            long[][] p = new long[2][n + 1];
            for (int i = 1; i <= n; i++) {
                p[0][i] = p[0][i - 1] + grid[0][i - 1];
                p[1][i] = p[1][i - 1] + grid[1][i - 1];
            }
            long ans = Long.MAX_VALUE;
            for (int i = 1; i <= n; i++) {
                ans = Math.min(ans, Math.max(p[0][n] - p[0][i], p[1][i - 1]));
            }
            return ans;
        }
    }


    public void run() {
        int[] arr = InputUtil.toIntegerArray("[1,2,3]");
        System.out.println(new Solution().toString());
    }

    public static void main(String[] args) throws Exception {
        LC2017 an = new LC2017();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
